import * as ActionTypes from './ActionTypes';

const initState = [
  {
    value: '待办事项一',
    status: true
  },
  {
    value: '待办事项二',
    status: false
  }
]

export default (state = initState, action) => {
  switch (action.type) {
    case ActionTypes.ADDTODO:
      return [...state, { value: action.value, status: false }]
    case ActionTypes.COMPLETE:
      return state.map((todo, order) => action.order === order ? { ...todo, status: !todo.status } : todo)
    case ActionTypes.DELTODO:
      return state.filter((todo, order) => action.order !== order)
    default:
      return state
  }
}